package com.cykj.pos.controller.api;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.domain.UnFailureActiveTemplate;
import com.cykj.pos.service.IUnFailureActiveTemplateService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

/**
 * 未/伪激活模板Controller
 *
 * @author tzf
 * @date 2025-03-18
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/active" )
public class UnFailureActiveTemplateController extends BaseController {

    private final IUnFailureActiveTemplateService iUnFailureActiveTemplateService;

    /**
     * 查询未/伪激活模板列表
     */
    @PreAuthorize("@ss.hasPermi('pos:active:list')")
    @GetMapping("/list")
    public TableDataInfo list(UnFailureActiveTemplate unFailureActiveTemplate) {
        startPage();
        List<UnFailureActiveTemplate> list = iUnFailureActiveTemplateService.queryList(unFailureActiveTemplate);
        return getDataTable(list);
    }

    /**
     * 导出未/伪激活模板列表
     */
    @PreAuthorize("@ss.hasPermi('pos:active:export')" )
    @Log(title = "未/伪激活模板" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UnFailureActiveTemplate unFailureActiveTemplate) {
        List<UnFailureActiveTemplate> list = iUnFailureActiveTemplateService.queryList(unFailureActiveTemplate);
        ExcelUtil<UnFailureActiveTemplate> util = new ExcelUtil<UnFailureActiveTemplate>(UnFailureActiveTemplate.class);
        return util.exportExcel(list, "template" );
    }

    /**
     * 获取未/伪激活模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:active:query')" )
    @GetMapping(value = "/{tempId}" )
    public AjaxResult getInfo(@PathVariable("tempId" ) Long tempId) {
        return AjaxResult.success(iUnFailureActiveTemplateService.getById(tempId));
    }

    /**
     * 新增未/伪激活模板
     */
    @PreAuthorize("@ss.hasPermi('pos:active:add')" )
    @Log(title = "未/伪激活模板" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UnFailureActiveTemplate unFailureActiveTemplate) {
        return toAjax(iUnFailureActiveTemplateService.save(unFailureActiveTemplate) ? 1 : 0);
    }

    /**
     * 修改未/伪激活模板
     */
    @PreAuthorize("@ss.hasPermi('pos:active:edit')" )
    @Log(title = "未/伪激活模板" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UnFailureActiveTemplate unFailureActiveTemplate) {
        return toAjax(iUnFailureActiveTemplateService.updateById(unFailureActiveTemplate) ? 1 : 0);
    }

    /**
     * 删除未/伪激活模板
     */
    @PreAuthorize("@ss.hasPermi('pos:active:remove')" )
    @Log(title = "未/伪激活模板" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{tempIds}" )
    public AjaxResult remove(@PathVariable Long[] tempIds) {
        return toAjax(iUnFailureActiveTemplateService.removeByIds(Arrays.asList(tempIds)) ? 1 : 0);
    }
}
